<template>
  <div class="m-16px">
    <Form ref="form" :model="model" :rules="validationRules">
      <FormItem label="编码" required prop="code">
        <Input placeholder="请输入项目编码" v-model="model.code"/>
      </FormItem>
      <FormItem label="名称" required prop="name">
        <Input placeholder="请输入项目名称" v-model="model.name"/>
      </FormItem>
    </Form>
    <div class="layui-layer-btn layui-layer-btn-r">
      <Button icon="fa fa-close" @click="$emit('close')" :loading="loading">
        取消
      </Button>
      <Button icon="fa fa-save" color="primary" @click="confirm" :loading="loading">
        保存
      </Button>
    </div>
  </div>
</template>

<script>
/**
 * @功能描述: 项目FORM
 * @创建时间: 2023年08月08日
 * @公司官网: www.fenxi365.com
 * @公司信息: 纷析云（杭州）科技有限公司
 * @公司介绍: 专注于财务相关软件开发, 企业会计自动化解决方案
 */
import Project from "@js/api/Project";
import {message} from "heyui";
import {CopyObj} from "@common/utils";

export default {
  name: "ProjectForm",
  props: {
    entity: Object,
  },
  data() {
    return {
      loading: false,
      model: {
        id: null,
        code: null,
        name: null,
      },
      validationRules: {
      }
    }
  },
  methods: {
    confirm() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        this.loading = true;
        Project.save(this.model).then(() => {
          message("保存成功~");
          this.$emit('success');
        }).finally(() => this.loading = false);
      }
    },
  },
  created() {
    CopyObj(this.model, this.entity);
  }
}
</script>
